﻿Public Class VistaDinamicaUsuarios
    Public Sub ResumenUser()

        Try
            Dim permisosCount As Integer = ConexionSGS.EjecutarQueryScalar(String.Format("select	count(idclase) from usuarios as a inner join roles as b on a.idrol = b.idrol  inner join seg_roldetalle as c on b.idrol = c.idrol where a.iduser = {0}", txtiduser.Text))
            Dim facturasCount As Integer = ConexionSGS.EjecutarQueryScalar(String.Format("select count(b.idfactura) from facturas as a inner join facturasdetalle as b on a.idfactura = b.idfactura where iduser = {0}", txtiduser.Text))
            Dim mensajesCount As Integer = ConexionSGS.EjecutarQueryScalar(String.Format("select count(idmensaje) from tmensajes where iduser = {0}", txtiduser.Text))
            Dim permisosTotal As Decimal = ConexionSGS.EjecutarQueryScalar("select count(idclase) from seg_clases")
            Dim facturasTotal As Decimal = ConexionSGS.EjecutarQueryScalar("select count(idfactura) from facturasdetalle")
            Dim mensajesTotal As Decimal = ConexionSGS.EjecutarQueryScalar("select count(idmensaje) from tmensajes")
            Dim permisoPromedio As Decimal = (permisosCount / permisosTotal) * 100
            Dim facturasPromedio As Decimal = (facturasCount / facturasTotal) * 100
            Dim mensajesPromedio As Decimal = (mensajesCount / mensajesTotal) * 100
            porpermiso.Text = permisoPromedio
            facprom.Text = facturasPromedio
            menprom.Text = mensajesPromedio
            Txtxpermisos.Text = permisosCount
            txtfaxturas.Text = facturasCount
            txtmensajes.Text = mensajesCount
        Catch ex As Exception
            LogSGS.RegistrarLogSinEnviarCorreo(My.Resources.StringGlobal.prgVinicio, "Error en la función ResumenUser", ex, My.Resources.StringGlobal.mdlSeguridad, Name, "ResumenUser")
        End Try
    End Sub

    Private Sub VistaDinamicaUsuarios_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Try
            'TODO: This line of code loads data into the 'DbFireAndIceDataSet._roles' table. You can move, or remove it, as needed.
            Me.RolesTableAdapter1.Fill(Me.DbFireAndIceDataSet._roles)
            'TODO: This line of code loads data into the 'DbFireAndIceDataSet.usuarios' table. You can move, or remove it, as needed.
            Me.UsuariosTableAdapter.Fill(Me.DbFireAndIceDataSet.usuarios)
        Catch ex As Exception
            LogSGS.RegistrarLogSinEnviarCorreo(My.Resources.StringGlobal.prgVinicio, "Error al cargar los datos en el Load", ex, My.Resources.StringGlobal.mdlSeguridad, Name, sender.GetType.FullName.ToString)
        End Try
    End Sub

    Private Sub txtiduser_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtiduser.TextChanged
        ResumenUser()
    End Sub
End Class